import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'

function options(_this) {
  return [
    {
      field: 'name',
      title: '广告名称',
      minWidth: 100
    },
    {
      field: 'viewCount',
      title: '浏览次数',
      minWidth: 150
    },
    {
      field: 'displayOrder',
      title: '展示顺序',
      minWidth: 140,
      visible: _this.tabVal == 1
    },
    // {
    //   field: '',
    //   title: '调整排序',
    //   minWidth: 140,
    //   visible: _this.tabVal == 1,
    //   slots: {
    //     default: (params, h) => {
    //       let len = _this.upList && _this.upList.length ? _this.upList.length : 0
    //       let btns = []
    //       let index = params.rowIndex
    //       btns.push({
    //         type: 'md-arrow-round-up',
    //         style: {
    //           fontSize: "20px",
    //           color: index == 0 ? "#999" : 'rgb(217, 0, 27)',
    //           cursor: 'pointer'
    //         },
    //         event:'moveUp',
    //         data: params
    //       })
    //       btns.push({
    //         type: 'md-arrow-round-down',
    //         style: {
    //           fontSize: "20px",
    //           color: index + 1 == len ? "#999" : 'rgb(51, 102, 255)',
    //           cursor: 'pointer'
    //         },
    //         event:'moveDown',
    //         data: params
    //       })
    //       return table.cell.icon(_this, h, btns)
    //     }
    //   },
    // },
    {
      field: 'updateUser',
      title: '操作人',
      minWidth: 80
    },
    {
      field: 'updateTime',
      title: '操作时间',
      minWidth: 120
    },
    {
      field: 'handles',
      title: '操作项',
      width: 210,
      fixed: 'right',
      slots: {
        default: (params, h) => {
          let btns = []
          let item = params.row
          if (_this.tabVal == 1) {
            return [
              h(
                'Poptip',
                {
                  props: {
                    transfer: true,
                    width: '200',
                    trigger: 'click',
                    disabled: !item.multiOrgFlag
                  }
                },
                [
                  h(
                    'Button',
                    {
                      props: {
                        type: 'text'
                      },
                      style: {
                        color: '#0F42A7',
                        cursor: 'pointer'
                      },
                      on: {
                        click: () => {
                          _this.offShelf(params.row)
                        }
                      }
                    },
                    '下架'
                  ),
                  h(
                    'div',
                    {
                      slot: 'content',
                      style: {
                        color: '#0F42A7',
                        cursor: 'pointer',
                        display: 'flex',
                        flexDirection: 'column'
                      }
                    },
                    [
                      h(
                        'Button',
                        {
                          props: {
                            type: 'text'
                          },
                          style: {
                            borderRadius: '0',
                            borderBottom: '1px solid #ccc',
                            color: '#0f42a7'
                          },
                          on: {
                            click: () => {
                              _this.offShelfCur(params.row)
                            }
                          }
                        },
                        '在当前组织下架'
                      ),
                      h(
                        'Button',
                        {
                          props: {
                            type: 'text'
                          },
                          style: {
                            borderRadius: '0',
                            color: '#0f42a7'
                          },
                          on: {
                            click: () => {
                              _this.offShelfAll(params.row)
                            }
                          }
                        },
                        '在全部组织下架'
                      )
                    ]
                  )
                ]
              ),
              h(
                'Poptip',
                {
                  props: {
                    transfer: true,
                    width: '200',
                    trigger: 'click',
                    disabled: !item.multiOrgFlag
                  }
                },
                [
                  h(
                    'Button',
                    {
                      props: {
                        type: 'text'
                      },
                      style: {
                        color: '#0F42A7',
                        cursor: 'pointer',
                        display: item.displayOrder == 1 ? 'none' : ''
                      },
                      on: {
                        click: () => {
                          _this.topping(params.row)
                        }
                      }
                    },
                    '置顶'
                  ),
                  h(
                    'div',
                    {
                      slot: 'content',
                      style: {
                        color: '#0F42A7',
                        cursor: 'pointer',
                        display: 'flex',
                        flexDirection: 'column'
                      }
                    },
                    [
                      h(
                        'Button',
                        {
                          props: {
                            type: 'text'
                          },
                          style: {
                            borderRadius: '0',
                            borderBottom: '1px solid #ccc',
                            color: '#0f42a7'
                          },
                          on: {
                            click: () => {
                              _this.toppingCur(params.row)
                            }
                          }
                        },
                        '在当前组织置顶'
                      ),
                      h(
                        'Button',
                        {
                          props: {
                            type: 'text'
                          },
                          style: {
                            borderRadius: '0',
                            color: '#0f42a7'
                          },
                          on: {
                            click: () => {
                              _this.toppingAll(params.row)
                            }
                          }
                        },
                        '在全部组织置顶'
                      )
                    ]
                  )
                ]
              ),

              h(
                'Button',
                {
                  props: {
                    type: 'text'
                  },
                  style: {
                    cursor: 'pointer',
                    padding: '0 10px',
                    color: '#0F42A7',
                    display:
                      item.type == 'NORMAL' || (item.type == 'SPECIAL' && item.skipMode == 'DETAIL_PAGE')
                        ? ''
                        : 'none'
                  },
                  on: {
                    click: (e) => {
                      e.stopPropagation()
                      _this.previewFun(params.row)
                    }
                  }
                },
                '预览'
              )
            ]
          } else {
            btns.push({
              title: '上架',
              event: 'upShelf',
              data: item
            })
            btns.push({
              title: '编辑',
              event: 'editFun',
              data: item
            })
            btns.push({
              title: '删除',
              event: 'deleteFun',
              data: item
            })
          }
          if (item.type == 'NORMAL' || (item.type == 'SPECIAL' && item.skipMode == 'DETAIL_PAGE')) {
            btns.push({
              title: '预览',
              event: 'previewFun',
              data: item
            })
          }
          return table.cell.btns(_this, h, btns)
        }
      }
    }
  ]
}

export default {
  options
}
